package com.jy.api.controller.pos;

import com.jy.api.dao.NoticeDao;
import com.jy.api.util.MyDateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by lihu on 2018/3/3.
 */

@Slf4j
@RestController
@RequestMapping(value = "v1/pos", produces = "application/json;charset=utf-8")
public class NoticController {


    @Autowired
    NoticeDao noticeDao;

    /**
     * 查看呼叫历史
     *
     * @param storeId
     * @param pageable
     * @return
     */
    @RequestMapping(value = "/{storeId}/notic", method = RequestMethod.GET)
    public ResponseEntity getNotic(@PathVariable String storeId,
                                   @PageableDefault(value = 15, sort = {"addTime"}, direction = Sort.Direction.DESC) Pageable pageable) {

        try {
            return new ResponseEntity(noticeDao.findByStoreIdAndAddTimeAfter(storeId,
                    MyDateUtils.increaseDate(new Date(), -1), pageable), HttpStatus.OK);
        } catch (Exception ex) {
            log.error("getNotic is error storeId:{}", storeId);
            return new ResponseEntity("系统运行错误", HttpStatus.INTERNAL_SERVER_ERROR);
        }

    }
}
